#include "LCD1602.h"

void LCD_Init()
{
    LCD_WriteCommand(0x38); //设置8位格式，2行，5*7
    LCD_WriteCommand(0x0c); //整体显示，关光标，不闪烁
    LCD_WriteCommand(0x06); //设定输入方式，增量不移位
    LCD_WriteCommand(0x01); //清除屏幕
    //LCD_WriteCommand(0x80); //设置数据指针起点

    Delay_40us(100);
}

void LCD_WriteCommand(uchar cmd)
{
    LCD_DB = cmd;
    LCD_RS = 0;
    LCD_RW = 0;
    LCD_EN = 1;
    Delay_40us(1);
    LCD_EN = 0;
    Delay_40us(1);
}

void LCD_WriteData(uchar dat)
{
    LCD_DB = dat;
    LCD_RS = 1;
    LCD_RW = 0;
    LCD_EN = 1;
    Delay_40us(1);
    LCD_EN = 0;
    Delay_40us(1);
}

void LCD_DisplayChar(uchar row, uchar column, uchar dat)
{
    uchar address;

    switch (row)
    {
    case 1:
        address = 0x80 + column;
        break;
    case 2:
        address = 0xc0 + column;
        break;
    }

    LCD_WriteCommand(address);
    LCD_WriteData(dat);
}